package org.sky.sys.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.sky.sys.entity.SysOrgan;
import org.sky.sys.service.SysOrganService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//@Controller
@RestController
@RequestMapping("/sysOrgan")
public class SysOrganController {
    @Autowired
    private SysOrganService sysOrganService;

    @PostMapping(value = "/add")
    public boolean add(@RequestBody SysOrgan sysOrgan){
        sysOrganService.insertSysOrgan(sysOrgan);
        return true;
    }
    @GetMapping(value = "/get/{code}")
    @HystrixCommand(fallbackMethod = "processHystrix_Get")
    public SysOrgan get(@PathVariable String code){
        return sysOrganService.get(code);
    }
    @GetMapping(value = "/list")
    public List list(@RequestBody Map filter){
        return sysOrganService.selectByFilter(filter);
    }

    public SysOrgan processHystrix_Get(@PathVariable String code){
        return new SysOrgan().setId("404")
                .setCode("404")
                .setName("未找到该部门:processHystrix_Get()");
    }
}
